<template>
	<view>
		  
			<view class="items">
				<view class="left">手机号</view>
				<view class="right">
					<input type="text" v-model="phone" value="" placeholder="请输入" />
					<!-- <image class="arrow_right" src="https://www.atuanjian.com/appletStatic/static/right.png" mode=""></image> -->
				</view>
			</view>
			<view class="items">
				<view class="left">手机验证码</view>
				<view class="right">
					<input type="text" v-model="security_code" value="" placeholder="请输入" /> 
					<view class="code" v-if="isSend" @click="getCode">获取验证码</view>
				</view>
			</view>
			<view class="items">
				<view class="left">原始登录密码</view>
				<view class="right">
					<input type="text" v-model="password" value="" placeholder="请输入" /> 
				</view>
			</view>
			<view class="items">
				<view class="left">新密码</view>
				<view class="right">
					<input type="text" v-model="new_password" value="" placeholder="请输入" /> 
				</view>
			</view>
			
			   
		
		<view class="footer">
			<view class="submit" @click="sure">确定</view>
		</view> 
		
	</view>
</template>

<script>
	import {sendCode,editPassword} from '@/utils/request.js'
	
	export default {
		data() {
			return {
				userInfo:JSON.parse(uni.getStorageSync('userInfo')||{}),
				isSend:true,
				phone:'',
				password:'',
				new_password:'',
				security_code:'',
			}
		},
		methods: {
			sure(){
				if(!this.phone.trim()){
					uni.showToast({
						title:'请输入手机号',
						icon:'none'
					})
					return;
				}
				if(!this.security_code.trim()){
					uni.showToast({
						title:'请输入验证码',
						icon:'none'
					})
					return;
				}
				if(!this.password.trim()){
					uni.showToast({
						title:'请输入原始密码',
						icon:'none'
					})
					return;
				}
				if(!this.new_password.trim()){
					uni.showToast({
						title:'请输入新密码',
						icon:'none'
					})
					return;
				}
				if(this.password.trim()!=this.new_password.trim()){
					uni.showToast({
						title:'密码不一致',
						icon:'none'
					})
					return;
				}
				let data={
					token:this.userInfo.token,
					phone:this.phone,
					password:this.password,
					new_password:this.new_password,
					security_code:this.security_code,
				}
				this.editPassword(data).then(res=>{
					uni.showToast({
						title:'修改完成',
						duration:1500
					})
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},1500)
				})
			},
			async editPassword(data){
				return await editPassword(data)
			},
			async sendCode(data){
				return await sendCode(data)
			},
			getCode(){
				if(!this.phone.trim()){
					uni.showToast({
						title:'请输入手机号',
						icon:'none',
						duration:2000
					})
					return
				}else if(!/^1[3-9]\d{9}$/.test(this.phone.trim())){
					uni.showToast({
						title:'手机号格式有误',
						icon:'none',
						duration:2000
					})
					return
				}else{ 
					if(!this.isSend){
						return
					}
					this.isSend=false
					let data={
						phone:this.phone.trim()
					}
					this.sendCode(data).then(res=>{
						uni.showToast({
							title:'验证码10分钟内有效',
							icon:'none',
							duration:2000
						})
						this.color='#CCCCCC'
					}).catch(err=>{
						console.log(err)
					})
				}
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #F5F5F5;
}
.header{
	padding: 20rpx 24rpx;
}
.head{
	background-color: #FFFFFF;
	background-color: #FFFDFD;
	border-radius: 16rpx;
	padding: 40rpx 0;
	.title{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 40rpx;
		color: #1A1A1A;
		margin-bottom: 32rpx;
			text-align: center;
	}
	.select{
		display: flex;
		justify-content: center;
		align-items: center;
		.item{
			width: 120rpx;
			height: 40rpx;
			text-align: center;
			line-height: 40rpx;
			background: #EBEBEB; 
			border-radius: 4rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400; 
			color: #1A1A1A;
			margin: 0 20rpx;
		}
		
		.active{
			background-color: #FFB850;
			color: #FFFFFF;
		}
	}
	
}
.code{
	border-radius: 8rpx;
	padding: 4rpx 8rpx;
	background-color:#FFB850 ;
	color: #FFFFFF;
	font-size: 24rpx;
	line-height: 30rpx;
	margin-left: 16rpx;
}
.items{
	background-color: #FFFFFF;
	padding: 24rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid #F5F5F5;
	.left{
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 40rpx;
		color: #1A1A1A;
	}
	.right{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		input{
			margin: 0;
			padding: 0;
			border: none;
			outline: none;
			background-color: #FFFFFF;
			text-align: right;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 40rpx;
			color: #999999;
		}
	}
}
.arrow_right{
	width: 20rpx;
	height: 20rpx;
}
.footer{ 
		margin-top: 120rpx;
		.submit{
			width: 670rpx;
			height: 92rpx;
			background: linear-gradient(98deg, #FFB850 0%, #FF8000 100%);
			opacity: 0.92;
			text-align: center;
			border-radius: 46rpx;
			margin: 0 auto;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 92rpx;
			color: #FFFFFF;
		}
	}
	.desc{
		text-align: center;
		margin-top: 24rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 34rpx;
		color: #888888;
	}
</style>
